package com.xfxz.merchant.myapplication;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by King on 2017/2/10.
 */

public class MyApplication extends Application {
    private static Context  mContext;
    private List<Activity> mActivityList  = new ArrayList<>();
    private static MyApplication mMyApplication;
    public static final String TAG = MyApplication.class.getSimpleName();
    public static MyApplication getInstance(){
        if(mMyApplication == null){
            mMyApplication = new MyApplication();
        }
        return mMyApplication;
    }
    @Override
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();
    }

    public static Context getContext(){
        return mContext;
    }

    /**
     * 添加activity
     * @param activity 当前activity
     */
    public void addActivity(Activity activity){
        mActivityList.add(activity);
        Log.e(TAG, "addActivity: "+activity.getLocalClassName()+"init" );
    }
    public void exit(Activity activity){
        activity.finish();
        mActivityList.remove(activity);
        Log.e(TAG, "addActivity: "+activity.getLocalClassName()+"exit" );
    }
    /**
     * 全部退出
     */
    public void exitAll(){
        Log.e(TAG, "addActivity: exitall" );
        for (Activity activity : mActivityList) {
            mActivityList.remove(activity);
            activity.finish();
        }
    }
}
